package com.humngyang.com.hmy.study.shuzu;




/**
 *   Description: 栈和队列
 *   Author: humingyang
 *   Date: 2020/1/7 14:31
 *
 *   栈的特点：先进后出、后进先出   相当于水桶
 *   队列特点：先进先出，后进后出   相当于水管
 *
 */
public class Stack {

    //栈的底层是一个数组实现的
    private long[] arr;
    //栈顶
    private int top;

    //默认的构造方法
    public Stack() {
        arr = new long[4];
        top = -1;
    }

    //根据传入的数组初始化栈的大小
    public Stack(int maxsize) {
        arr = new long[maxsize];
        top = -1;
    }

    //添加数据
    public void mypush(long value) {
        arr[++top] = value;
    }

    //查看并移除
    public long mypop() {
        return arr[top--];
    }

    //查看数据
    public long mypeek() {
        return arr[top];
    }

    //判断是否满
    public boolean myisfull() {
        return top == arr.length - 1;
    }
    //判断是否为空

    public boolean myidEmpty() {
        return top == -1;
    }


    //栈的长度
    public int mulength (){
        return top;
    }

}
